package sortAlgorithm;

/**
 * 选择排序
 * 
 * @author YNS
 *
 */
public class SelectionSort {
	public static int[] sort(int[] source) {
		int temp;
		int index = -1;

		for (int i = 0; i < source.length - 1; i++) {
			index = i;
		
			for (int j = i + 1; j < source.length; j++) {
				if (source[index] > source[j]) {
					index = j;
				}
			}
			// 将一趟下来求出的最小数，与这个数交换
			if (index > 0) {
				temp = source[i];
				source[i] = source[index];
				source[index] = temp;
			}
			
//			 System.out.println(Arrays.toString(source));
		}

		return source;
	}
}
